<?php 
	include 'header.php';
	//获取三个商品列表
	
	//新品
	$stmt = $pdo->prepare('select gid,gname,gphoto,price,zkprice,newdate from kp_goods where gzt=0 order by newdate desc,gid desc limit 8');
	$stmt->execute();
	$arrNews = $stmt->fetchAll(PDO::FETCH_ASSOC);
	//print_r($arrNews);
	//热卖(暂时无销售数据,用库存数量代替)
	$stmt = $pdo->prepare('select a.gid,a.gname,a.gphoto,a.price,a.zkprice,b.num from kp_goods a left join (select gid,sum(num) num from kp_sell group by gid) b on a.gid = b.gid where a.gzt=0 order by b.num desc limit 8');
	$stmt->execute();
	$arrRes = $stmt->fetchAll(PDO::FETCH_ASSOC);
	//折扣前4
	$stmt = $pdo->prepare('select gid,gname,gphoto,price,zkprice from kp_goods where gzt=0 order by (price - zkprice) desc,gid desc limit 8');
	$stmt->execute();
	$arrZks = $stmt->fetchAll(PDO::FETCH_ASSOC);
	
	?>
<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
		<link rel="stylesheet" type="text/css" href="css/index.css"/>
		<title>主页</title>
	</head>
	<body>
		<?php
		
		?>
		<div id="index">
			<!--图片广告-->
			<div class="imgs">
				<img src="images/ad-04.jpg" width="985px"/>
			</div>
			<!--各种推荐-->
			<div class="goods">
				<div class="title">
					<h2>新品推荐</h2>
					<div class="move">
						<a href="goodslist.php?new=100">更多>></a>
					</div>
				</div>
				<div class="goods_re">
					<!--商品-->
					<?php
					 foreach($arrNews as $good){
					 	$gphotos = [];
						if(!empty($good['gphoto'])){
							$gphotos = explode(';', $good['gphoto']);
						}
						
					 	
					?>
					<div class="good">
						<img src="<?php if(!empty($gphotos[0])) echo  $gphotos[0]; else echo 'upload/good_001.gif'; ?>"/>
						<h4 class="title" title="<?php echo $good['gname']; ?>"><?php echo $good['gname']; ?></h4>
						<ul class="info">
							<li class="pricenow"><span class="yuan">¥</span><?php echo $good['zkprice']; ?></li>
							<li class="pricedel">¥<?php echo $good['price']; ?></li>
							<a href="info.php?gid=<?php echo $good['gid']; ?>"><li class="going">购买</li></a>
						</ul>
					</div>
					<?php
					 }
					?>
					<!--商品-->
					<!--<div class="good">
						<img src="upload/good_001.gif"/>
						<h4 class="title" title="第一件商品测试文本长度尽量溢出,好做处理">第一件商品测试文本长度尽量溢出,好做处理</h4>
						<ul class="info">
							<li class="pricenow"><span class="yuan">¥</span>200.00 </li>
							<li class="pricedel">¥220.00</li>
							<li class="going">购买</li>
						</ul>
					</div>-->
					<!--商品-->

				</div>
			</div><!--各种推荐end-->
			<!--各种推荐-->
			<div class="goods" style="margin-top: 20px;">
				<div class="title">
					<h2>人气热卖</h2>
					<div class="move">
						<a href="goodslist.php?re=100">更多>></a>
					</div>
				</div>
				<div class="goods_re">
					<!--商品-->
					<?php
					 foreach($arrRes as $good){
					 	$gphotos = [];
						if(!empty($good['gphoto'])){
							$gphotos = explode(';', $good['gphoto']);
						}
					?>
					<div class="good">
						<img src="<?php if(!empty($gphotos[0])) echo  $gphotos[0]; else echo 'upload/good_001.gif'; ?>"/>
						<h4 class="title" title="<?php echo $good['gname']; ?>"><?php echo $good['gname']; ?></h4>
						<ul class="info">
							<li class="pricenow"><span class="yuan">¥</span><?php echo $good['zkprice']; ?></li>
							<li class="pricedel">¥<?php echo $good['price']; ?>/li>
							<a href="info.php?gid=<?php echo $good['gid']; ?>"><li class="going">购买</li></a>
						</ul>
					</div>
					<?php
					 }
					?>
				</div>
			</div><!--各种推荐end-->
			<!--各种推荐-->
			<div class="goods" style="margin-top: 20px;">
				<div class="title">
					<h2>折扣专区</h2>
					<div class="move">
						<a href="goodslist.php?zk=100">更多>></a>
					</div>
				</div>
				<div class="goods_re">
					<!--商品-->
					<?php
					 foreach($arrZks as $good){
					 	$gphotos = [];
						if(!empty($good['gphoto'])){
							$gphotos = explode(';', $good['gphoto']);
						}
					?>
					<div class="good">
						<img src="<?php if(!empty($gphotos[0])) echo  $gphotos[0]; else echo 'upload/good_001.gif'; ?>"/>
						<h4 class="title" title="<?php echo $good['gname']; ?>"><?php echo $good['gname']; ?></h4>
						<ul class="info">
							<li class="pricenow"><span class="yuan">¥</span><?php echo $good['zkprice']; ?></li>
							<li class="pricedel">¥<?php echo $good['price']; ?>/li>
							<a href="info.php?gid=<?php echo $good['gid']; ?>"><li class="going">购买</li></a>
						</ul>
					</div>
					<?php
					 }
					?>
				</div>
			</div><!--各种推荐end-->
		</div>
		<?php
		include 'bottom.php';
		?>
	</body>
</html>